const cloud = require('wx-server-sdk')

cloud.init({
  // API 调用都保持和云函数当前所在环境一致
  env: cloud.DYNAMIC_CURRENT_ENV
})

// 云函数入口函数
exports.main = async (event, context) => {

  console.log(event)

  const { OPENID } = cloud.getWXContext()

  const result = await cloud.openapi.subscribeMessage.send({
    touser: OPENID,
    templateId:'0NAN_O3MgKXxCwOdxMeLfrJV96DaSuv-Z53Sp0hgGIQ',
    miniprogram_state: 'developer',
    
    // 此处字段应修改为所申请模板所要求的字段
    data: {
      name3: {
        value: '咖啡',
      },
      thing5:{
        value:'2',
      },
      time2: {
        value: '2020-01-01 00:00',
      },
      thing1:{
        value:'xxx'
      },
      thing4:{
        value:'im already hurt'
      }
    }
  })

  console.log(result)

  return result
}
